package com.ben.notebook.infrastructure.util;

/**
 * 自定义响应数据结构封装类
 * @date 2020-11-22
 */
public class JsonResult {

    private String status;
    private String errorMsg;
    private Object data;

    private JsonResult(){}

    private JsonResult(Object data){
        this.status = StatusEnum.OK.getValue();
        this.errorMsg = null;
        this.data = data;
    }

    private JsonResult(String status, String errorMsg, Object data){
        this.status = status;
        this.errorMsg = errorMsg;
        this.data = data;
    }

    public static JsonResult error(ErrorMsgEnum errorMsgEnum) {
        return JsonResult.error(errorMsgEnum.getErrorMsg());
    }

    public static JsonResult error(String errorMsg) {
        return new JsonResult(StatusEnum.ERROR.getValue(), errorMsg, null);
    }

    public static JsonResult ok() {
        return new JsonResult(null);
    }

    public static JsonResult ok(Object data) {
        return new JsonResult(data);
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
